﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace VentAnalyServer.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class ToolContorller : ControllerBase
    {
        private readonly ILogger<ToolContorller> _logger;

        public ToolContorller(ILogger<ToolContorller> logger)
        {
            _logger = logger;
        }


        [HttpPost("unzip")]
        public IActionResult UnZipString(JObject resource)
        {
            // Console.WriteLine("[/tool/unzip]:{0}", resource.ToString());
            try
            {
                object data = JsonConvert.DeserializeObject(ZipUtil.GZipDecompressString(resource["zipstr"].ToObject<string>()));
                return ApiUtil.Ok(data);
            }
            catch (Exception e)
            {
                Console.WriteLine("[ERROR] url: /tool/unzip, message:{0}", e.Message);
                return ApiUtil.Error(e.Message);
            }
        }
    }
}
